#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void helper(int** a, int** b, int v, int h) {
    for (int i = 0; i < v; i++) {
        for (int j = 0; j < h; j++) {
            a[i][j] += b[i][j];
        }
    }
    int count = 0;
    for (int i = 0; i < v; i++) {
        //统计行
        int flag = 1;
        for (int j = 0; j < h; j++) {
            if (a[i][j] != 0) {
                flag = 0;
                break;
            }
        }
        if (flag)
            count++;
    }
    for (int i = 0; i < h; i++) {
        //统计列
        int flag = 1;
        for (int j = 0; j < v; j++) {
            if (a[j][i] != 0) {
                flag = 0;
                break;
            }
        }
        if (flag)
            count++;
    }
    printf("%d\n", count);
}

int main() {
    int vertical, horizon;
    FILE* fp = fopen("./data.in", "r");
    while (fscanf(fp, "%d %d", &vertical, &horizon) != EOF && vertical != 0) {
        int **matric_A, **matric_B;
        matric_A = (int**)malloc(vertical * sizeof(int*));
        matric_B = (int**)malloc(vertical * sizeof(int*));
        for (int i = 0; i < vertical; i++) {
            matric_A[i] = (int*)malloc(horizon * sizeof(int));
            matric_B[i] = (int*)malloc(horizon * sizeof(int));
        }
        for (int i = 0; i < vertical; i++) {
            for (int j = 0; j < horizon; j++) {
                fscanf(fp, "%d", &matric_A[i][j]);
            }
        }
        for (int i = 0; i < vertical; i++) {
            for (int j = 0; j < horizon; j++) {
                fscanf(fp, "%d", &matric_B[i][j]);
            }
        }
        helper(matric_A, matric_B, vertical, horizon);
    }
}